package com.example.config;

import com.example.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Description:2.注册配置拦截器
 * User: bjc
 * Date: 2025-10-09
 * Time: 20:27
 */
@Configuration
public class AppInterceptorConfigurer implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //1.添加登录拦截器
        registry.addInterceptor(loginInterceptor) //添加用户登录拦截器
                //2.添加拦截路径，拦截所有请求
                .addPathPatterns("/**")
                //3.排除拦截路径
                .excludePathPatterns("/sign-in.html")    //排除登录页面
                .excludePathPatterns("/sign-up.html")    //排除注册页面
                .excludePathPatterns("/user/login")      //排除登录接口
                .excludePathPatterns("/user/register")   //排除注册接口
                .excludePathPatterns("/user/logout")     //排除退出接口
                .excludePathPatterns("/swagger*/**")     //排除swagger接口和所有静态文件
                .excludePathPatterns("/v3*/**")
                .excludePathPatterns("/dist/**")
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/**.ico");
    }
}
